﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Adnc.Infra.Helper
{
    /// <summary>
    /// 时间
    /// </summary>
    public static class TimeHelper
    {
        public static string GetTimeSpanStr(DateTime time)
        {
            if (DateTime.Now < time)
                return "";
            TimeSpan span = DateTime.Now - time;
            if (span.TotalDays > 365)
            {
                int year = (int)span.TotalDays / 365;
                return $"{year}年前";
            }
            else if (span.TotalDays >= 30)
            {
                int mouth = (int)span.TotalDays / 30;
                return $"{mouth}个月前";
            }
            else if (span.TotalDays >= 1)
            {
                return $"{Math.Floor(span.TotalDays)}天前";
            }
            else if (span.TotalHours >= 1)
            {
                return $"{Math.Floor(span.TotalHours)}小时前";
            }
            else if (span.TotalMinutes >= 1)
            {
                return $"{Math.Floor(span.TotalMinutes)}分钟前";
            }
            else
                return $"{Math.Floor(span.TotalSeconds)}秒钟前";
        }
    }
}
